package cn.edu.nit.sys.mapper;

import cn.edu.nit.sys.entity.Files;
import cn.edu.nit.sys.entity.Student;
import cn.edu.nit.sys.entity.Teacher;
import cn.edu.nit.sys.entity.User;
import cn.edu.nit.sys.export.UserExport;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface FileMapper extends BaseMapper<Files> {

    @Insert("insert into sys_attach(id, attach_id, attach_name, uid, type) " +
            "values(#{id}, #{attachId}, #{attachName}, #{uid}, #{type})")
    Integer saveImageInfo(String id, String attachId, String attachName, String uid, String type);

    @Select("select a.username, a.enable, b.name as role, a.create_time as createTime " +
            "from sys_user a, sys_role b where a.role_id = b.id")
    List<UserExport> getAllUser();

    @Select("select id, name, ifnull(phone, '未填写') as phone, ifnull(email, '未填写') as email, state_name, create_time " +
            "from sys_teacher")
    List<Teacher> getAllTeacher();

    @Select("select a.id, a.name, ifnull(a.phone, '未填写') as phone, ifnull(a.email, '未填写') as email, " +
            "b.name as dept, b.major, concat(a.clazz, '班') as clazz, ifnull(a.sex, '未填写') as sex, " +
            "ifnull(a.address, '未填写') address, concat(a.grade, '级') as grade from sys_student a, sys_department b " +
            "where a.dept_id = b.dept_id and a.major_id = b.major_id")
    List<Student> getAllStudent();

    @Delete("delete from sys_attach where id = #{id}")
    int delSysAvatar(String id);
}
